export default {
  mounted() {
    this.$nextTick(() => {
      this.__bindTooltipHandlers();
    });
  },
  updated() {
    this.$nextTick(() => {
      this.__bindTooltipHandlers();
    });
  },
  beforeDestroy() {
  },
  methods: {
    __bindTooltipHandlers() {
      const els = document.querySelectorAll('[data-tooltip]');
      els.forEach(el => {
        if (el.__tooltipBound) return; // 防止重复绑定
        el.__tooltipBound = true;

        el.addEventListener('mouseenter', () => {
          const rect = el.getBoundingClientRect();
          const x = Math.round(rect.left + window.screenX);
          const y = Math.round(rect.top + window.screenY - 5);
          const text = el.getAttribute('data-tooltip');
          window.electronAPI?.show?.(x, y, text);
        });

        el.addEventListener('mouseleave', () => {
          window.electronAPI?.hide?.();
        });
      });
    }
  }
}